
array_s1=(10.14.212.18 10.14.122.134)
array_s2=(10.14.244.156 10.14.10.139)

# 打印数组长度
echo ${#array_s1[@]}
echo ${#array_s2[@]}


# 循环遍历 
#for   element in ${array_s1[@]};
#do
#       res=$(mongo  --host  ${element}  --quiet --eval 'printjson(db.isMaster().ismaster)')
#       echo $res $element
#       if [ $res == 'false' ];then
#               server1=$element
#        fi
#done

#echo $server1

function Get_mongo_secondary()
{
local  array=$1
        for   element in ${array[@]};
        do
              res=$(mongo  --host  ${element}  --quiet --eval 'printjson(db.isMaster().ismaster)')
         #       echo $res $element
                if [ $res == 'false' ];then
          local      server1=$element
        fi
done
        echo  $server1


           }
s1=`Get_mongo_secondary ${array_s1}`
echo $s1
s2=`Get_mongo_secondary ${array_s2}`
echo $s2